
package com.example.testutil.util.sql;

import com.example.testutil.util.LogUtil;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class MySqliteOpenHelper extends SQLiteOpenHelper {
    private static MySqliteOpenHelper mHelper;

    public static String sqlname = "raymond";

    public MySqliteOpenHelper(Context context, String name, CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MySqliteOpenHelper(Context context, String name) {
        this(context, name, null, 1);
    }

    public static synchronized MySqliteOpenHelper getInstance(Context context) {
        if (mHelper == null) {
            mHelper = new MySqliteOpenHelper(context, TableContants.SQLNAME);
        }
        return mHelper;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        LogUtil.d("oncreate db -------------");
        String sql = "create table   " + sqlname + " (" + TableContants.USER_ID + " integer primary key autoincrement,"
                + TableContants.USER_NAME + " verchar(20)," + TableContants.USER_NUM + " verchar(20),"
                + TableContants.USER_SEX + " verchar(20)" + " )";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // db.execSQL("ALTER TABLE person ADD phone VARCHAR(12) NULL ");
        // //往表中增加一列
        String sql = "drop table if exists" + sqlname;
        db.execSQL(sql);
        onCreate(db);
    }

}
